package cn.autumnorange.app.user.provider.rest;

import cn.autumnorange.app.common.dto.ResultDto;
import cn.autumnorange.app.common.rpc.lock.RPCIdempotentLockTarget;
import cn.autumnorange.app.user.api.AppUserService;
import cn.autumnorange.app.user.api.MoneyDto;
import cn.autumnorange.app.user.api.MoneyService;
import cn.autumnorange.app.user.api.dto.UserDetailDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class SysUserRest implements AppUserService, MoneyService {
  @Autowired private AppUserService appUserService;

  @Value("${server.port}")
  private int port;

  //
  //    @Override
  //    public JsonResult addUpdSysUser(InsertSysUserDto insertSysUserDto) {
  //        return null;
  //    }
  @RPCIdempotentLockTarget()
  @Override
  public ResponseEntity<ResultDto<UserDetailDto>> loadUserByUsername(String name) {
    log.info("auth重试userProvider服务 端口:" + port);
    //    try {
    //      Thread.sleep(2500);
    //    } catch (InterruptedException e) {
    //      e.printStackTrace();
    //    }
    return appUserService.loadUserByUsername(name);
  }

  @Override
  public ResponseEntity<ResultDto<UserDetailDto>> loginSuccess() {
    return appUserService.loginSuccess();
  }

  @Override
  public ResultDto<MoneyDto> add(
      @PathVariable(value = "money") Long money, @PathVariable(value = "version") Long version) {

    log.info("账号加钱:" + money);
    //    return new ResultDto<MoneyDto>("money服务加钱成功", null, "money/add");
    return null;
  }

  @Override
  public ResultDto<MoneyDto> getmoney() {

    //    return new ResultDto<MoneyDto>("money服务查询成功", null, "money/getmoney");
    return null;
  }

  @Override
  public ResultDto<MoneyDto> resetacc() {

    //    return new ResultDto<MoneyDto>("money服务重置成功", null, "money/resetacc");
    return null;
  }
}
